<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<div id="app">
  <cpn></cpn>
</div>
</body>
<template id="cpn">
  <ccpn></ccpn>
</template>

<template id="ccpn">
  <div>
    <div>我是子组件</div>
    <button @click="butClick">按钮</button>
  </div>
</template>
<script src="../js/vue.js"></script>
<script>

  let app = new Vue({
    el: "#app",
    data: {
      message: "aaa",
    },
    methods: {},
    components: {
      cpn: {
        template: "#cpn",
        data() {
          return {
            name: "我是cpn组件"
          }
        },
        components: {
          ccpn: {
            template: "#ccpn",
            methods: {
              butClick() {
                // 1.访问父组件$parent
                // console.log(this.$parent);
                // console.log(this.$parent.name);

                // 2.访问根组件$root
                console.log(this.$root);
                console.log(this.$root.message);
              }
            },
          }
        },
      }
    },
  });
</script>
</html>